<template>
    <a-card :bodyStyle="{ padding: 0 }">
        <span style="font-weight: bold;">已分配房间:</span>
        <a-table ref="table" size="small" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
            :dataSource="dataSourceWithRooms" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
            @change="handleTableChange"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, onSelect: handleSelectRow, columnTitle: ' ' }">
            <span slot="bookRoomNum" slot-scope="text, record">
                {{ record.roomCode ? record.roomCode.split(',').length : 0 }} / {{ text }}
            </span>
        </a-table>
    </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'

export default {
    name: 'WithRoomsList',
    mixins: [JeecgListMixin],
    props: {
        yudingdan: {
            type: Object,
            required: true,
        },
        disabled: {
            type: Boolean,
            default: false,
            required: false
        },
    },
    computed: {
        dataSourceWithRooms() {
            return this.dataSource.filter(item => item.roomCode !== null)
        },
    },
    data() {
        return {
            ipagination: {
                current: 1,
                pageSize: 5,
            },
            queryParam: {
                id: this.yudingdan.bookCode || 'NoFan'
            },
            url: {
                list: '/room/roomBookInfo/queryRoomBookInfoMxByMainId',
            },
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 40,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '房间类型',
                    align: "center",
                    dataIndex: 'roomTypeCode_dictText'
                },
                {
                    title: '入住模式',
                    align: "center",
                    dataIndex: 'checkInMode_dictText'
                },
                {
                    title: '预定房间数',
                    align: "center",
                    dataIndex: 'bookRoomNum',
                    scopedSlots: { customRender: 'bookRoomNum' },
                },
                {
                    title: '额定房价',
                    align: "center",
                    dataIndex: 'ratedHousePrice'
                },
                {
                    title: '折扣',
                    align: "center",
                    dataIndex: 'discount'
                },
                {
                    title: '房价',
                    align: "center",
                    dataIndex: 'roomPrice'
                },
                {
                    title: '分配房间号',
                    align: "center",
                    dataIndex: 'roomCode'
                },
            ]
        }
    },
    methods: {
        handleSelectRow(record, selected, selectedRows) {
            let obj = {
                record: record,
                selected: selected,
                selectedRows: selectedRows
            }
            this.$emit('selectWithRooms', obj)
        }
    }
}
</script>